package com.blt.car.me.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.blt.car.R;
import com.blt.car.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

import blt.app_core.api.purse.bean.VoucherVo;

/**
 * Created by xgp on 2017/7/5.
 */

public class RechargeAdapter extends BaseAdapter {
    private LayoutInflater inflater;

    private List<VoucherVo> voucherVos;

    public RechargeAdapter(Context context) {
        inflater = LayoutInflater.from(context);
        voucherVos = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return voucherVos.size();
    }

    @Override
    public Object getItem(int position) {
        return voucherVos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VoucherHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_recharge, parent, false);
            holder = new VoucherHolder();
            holder.plat = (TextView) convertView.findViewById(R.id.item_recharge_plat);
            holder.amount = (TextView) convertView.findViewById(R.id.item_recharge_amount);
            holder.time = (TextView) convertView.findViewById(R.id.item_recharge_time);
            convertView.setTag(holder);
        } else {
            holder = (VoucherHolder) convertView.getTag();
        }

        VoucherVo voucherVo = (VoucherVo) getItem(position);

        if(voucherVo.type==1){
            if (voucherVo.payChannel != null && voucherVo.payChannel.equals("weixin")) {
                holder.plat.setText("微信支付");
            } else {
                holder.plat.setText("支付宝支付");
            }
        }else{
            holder.plat.setText("充值赠送");
        }
        holder.amount.setText(voucherVo.amt / 100 + "元");
        holder.time.setText(StringUtils.getDay(voucherVo.createTime));
        return convertView;
    }

    public void addData(List<VoucherVo> list) {
        this.voucherVos.clear();
        this.voucherVos.addAll(list);
        notifyDataSetChanged();
    }

    class VoucherHolder {
        TextView plat;
        TextView amount;
        TextView time;
    }

}
